#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：turbo 
@File    ：resp_format.py
@Author  ：赵加响
@Date    ：2023/3/31 17:08 
@Desc    ：
"""
from bases.results import RESULT_OK, RESULT_NG
from bases.types import dict_list
from turbo.settings import NEW_API_FORMAT


def api_format(code, success, data: dict_list, msg: str = '', *args, **kwargs):
    if NEW_API_FORMAT:
        dic = {'code': code, 'success': success, 'data': data, 'msg': msg}
    else:
        result = RESULT_OK if success else RESULT_NG
        dic = {'code': code, 'result': result, 'data': data, 'exception': msg}

    dic.update(kwargs)
    return dic


def success_format(code, data: dict_list, msg: str = '', *args, **kwargs):
    return api_format(code, True, data, msg, *args, **kwargs)


def fail_format(code, data: dict_list, msg: str = '', *args, **kwargs):
    return api_format(code, False, data, msg, *args, **kwargs)
